package com.aia.ann.web.json;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;

import com.aia.ann.domain.Agent;
import com.aia.ann.service.ChiefService;
import com.cfh.util.Tools;
import com.opensymphony.xwork2.ActionSupport;

public class AnnChangeJson extends ActionSupport implements SessionAware {
	private static final Logger logger = Logger.getLogger(AnnChangeJson.class);

	private static final long serialVersionUID = 1L;
	private String old_password;
	private String new_password;
	private String new_password2;

	private Map session;
	
	private ChiefService chiefService;

	public void setSession(Map session) {
		this.session = session;
	}

	public Map getSession() {
		return session;
	}

	public String getOld_password() {
		return old_password;
	}

	public void setOld_password(String oldPassword) {
		old_password = oldPassword;
	}

	public String getNew_password() {
		return new_password;
	}

	public void setNew_password(String newPassword) {
		new_password = newPassword;
	}

	public String getNew_password2() {
		return new_password2;
	}

	public void setNew_password2(String newPassword2) {
		new_password2 = newPassword2;
	}

	public void setChiefService(ChiefService chiefService) {
		this.chiefService = chiefService;
	}

	public ChiefService getChiefService() {
		return chiefService;
	}
	

	public void validate() {
		try {
			Agent cust = (Agent) session.get("customer");
			if (cust == null) {
				addActionError("没有登录或会话超时");
				return;
			}
		} catch (Exception e) {
			addActionError("Unknown Error");
			logger.error("Unknown Error", e);
			return;
		}
	}
	

	public String execute() throws Exception {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("AnnChangeJson - start"); //$NON-NLS-1$
			}
			
			chiefService.updateAgentPassword(this);
			
			if (logger.isDebugEnabled()) {
				logger.debug("AnnChangeJson - end"); //$NON-NLS-1$
			}
			
			return Tools.smartReturn((ActionSupport) this);
		} catch (Exception e) {
			logger.error("Unknown Error:" + e, e);
			throw new RuntimeException(e);
		}
	}

}
